var express = require('express');
var app = express();          /*实例化*/
const cookieParse = require('cookie-parser')
var path = require('path');

var session = require('express-session');       /*保存用户信息*/

app.use(cookieParse('Odasbhn41854asdqw'));
//配置中间件  固定格式
app.use(session({
    secret: 'Odasbhn41854asdqw',     //秘钥
    cookie: { maxAge: 60 * 1000 * 60 * 24 },   //回话保存时间 一小时
    resave: false,   // 即使 session 没有修改也保存 session 值
    saveUninitialized: true,
}))
// app.use(router)

// //设置跨域访问
// app.all('*', function(req, res, next) {
//     res.header("Access-Control-Allow-Origin", "*");
//         res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
//     res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
//     res.header("X-Powered-By",' 3.2.1')
//     next();
// });

app.set('view engine', 'ejs');
app.use(express.static('public'));

app.use('/node_modules', express.static(path.join(__dirname, './node_modules')))

var bodypaser = require('body-parser')
// //app.use 使用中间件（插件）
// //解析json数据
app.use(bodypaser.json())
// //解析表单数据 x-www-form-urlencoded
app.use(bodypaser.urlencoded({ extended: false }))




var fileRouter = require('./routes/fileRouter.js');

var admin = require("./routes/admin.js");


app.use('/file', fileRouter);

app.use('/admin', admin);

app.use('/test', (req,res)=>{
    res.render('admin/addpagecopy');
});




app.listen(3001, '0.0.0.0', () => {
    console.log('http://127.0.0.1:3001/admin/login')
});



